<template>
    <d2-container type="card">
        <header>
            <el-form :inline="true" :model="selectFrom" class="demo-form-inline" size="mini">
                <el-form-item label="店铺名称">
                    <el-input v-model="selectFrom.name" placeholder="店铺名称" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getShopInfoData()">查询</el-button>
                </el-form-item>
            </el-form>
        </header>
        <footer>
            <el-table :data="tableData" border style="width: 100%" size="mini" :height="height">
                <el-table-column prop="image" label="封面" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.image">
                            <el-image style="width: 100px; height: 100px" :src="scope.row.imageUrlList[0]"
                                :preview-src-list="[scope.row.imageUrlList[0]]">
                            </el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="logoImage" label="LOGO" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.logoImage">
                            <el-image style="width: 100px; height: 100px" :src="scope.row.logoImageUrlList[0]"
                                :preview-src-list="[scope.row.logoImageUrlList[0]]">
                            </el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="id" label="店铺编号" align="center" width="150" fixed="left" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="name" label="店铺名称" align="center" width="150" fixed="left" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column label="店铺账号" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.shopAccount">{{ scope.row.shopAccount.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="fullName" label="联系人" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="phone" label="电话" align="center" width="120" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column label="入驻校区" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.comSchool">{{ scope.row.comSchool.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="address" label="地址" align="center" width="150" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="deliveryScope" label="配送范围" align="center" width="150" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="tradeBeginHour" label="营业开始小时" align="center" width="120" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="tradeEndHour" label="营业结束小时" align="center" width="120" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="isTrade" label="是否营业" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isTrade == 0">否</div>
                        <div v-if="scope.row.isTrade == 1">是</div>
                    </template>
                </el-table-column>
                <el-table-column prop="salesVolume" label="销量" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="startPrice" label="起价费" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="deliveryPrice" label="配送费" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="mainBusiness" label="主营业务" align="center" width="220" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="introduction" label="介绍" align="center" width="220" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="notice" label="公告" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="businessLicense" label="营业执照" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.businessLicense">
                            <el-image style="width: 100px; height: 100px" :src="scope.row.businessLicenseUrlList[0]"
                                :preview-src-list="[scope.row.businessLicenseUrlList[0]]">
                            </el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="operatePermit" label="经营许可证" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.operatePermit">
                            <el-image style="width: 100px; height: 100px" :src="scope.row.operatePermitUrlList[0]"
                                :preview-src-list="[scope.row.operatePermitUrlList[0]]">
                            </el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="examineState" label="审核状态" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-if="scope.row.examineState == 0">未通过</div>
                        <div v-if="scope.row.examineState == 1">已通过</div>
                        <div v-if="scope.row.examineState == 2">审核中</div>
                    </template>
                </el-table-column>
                <el-table-column prop="balance" label="余额" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="withdrawalTotal" label="提现总额" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column label="店铺类型" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.shopType">{{ scope.row.shopType.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="score" label="评分" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="evaluateTemplate" label="评价模板" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="isPerfect" label="是否完善信息" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isPerfect == 0">否</div>
                        <div v-if="scope.row.isPerfect == 1">是</div>
                    </template>
                </el-table-column>
                <el-table-column prop="isRecommend" label="是否推荐" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isRecommend == 0">否</div>
                        <div v-if="scope.row.isRecommend == 1">是</div>
                    </template>
                </el-table-column>
                <el-table-column prop="isOpenSave" label="是否开通储蓄" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isOpenSave == 0">否</div>
                        <div v-if="scope.row.isOpenSave == 1">是</div>
                    </template>
                </el-table-column>
                <el-table-column prop="saveExamineState" label="储蓄审核状态" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-if="scope.row.saveExamineState == 0">未通过</div>
                        <div v-if="scope.row.saveExamineState == 1">已通过</div>
                        <div v-if="scope.row.saveExamineState == 2">审核中</div>
                        <div v-if="scope.row.saveExamineState == 2">未提交</div>
                    </template>
                </el-table-column>
                <el-table-column prop="isDining" label="是否开启自动出餐" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isDining == 0">否</div>
                        <div v-if="scope.row.isDining == 1">是</div>
                    </template>
                </el-table-column>
                <el-table-column prop="diningTime" label="出餐时间" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="packingCharge" label="打包费" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="evaluateNum" label="评价次数" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="state" label="状态" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-if="scope.row.state == 0">冻结</div>
                        <div v-if="scope.row.state == 1">存在</div>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" align="center">
                </el-table-column>
                <el-table-column label="操作" align="center" width="110" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="danger" size="mini" v-if="scope.row.state == 1" @click="freezeShopInfoData(scope.row)">冻结</el-button>
                        <el-button type="primary" plain size="mini" v-if="scope.row.state == 0" @click="thawShopInfoData(scope.row)">解冻</el-button>
                        <el-button type="primary" plain size="mini">自定义打包费</el-button>
                        <el-button type="primary" plain size="mini">推荐</el-button>
                        <el-button type="primary" plain size="mini">取消推荐</el-button>
                        <el-button type="primary" plain size="mini">审核店铺开通储蓄</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block" style="text-align:center">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                    :page-sizes="[5, 10, 15, 20]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </footer>
    </d2-container>
</template>
  
<script>
import { getShopInfoBack, addShopInfo, updateShopInfo, freezeShopInfo,thawShopInfo } from "@/api/modules/shop_info.js"
export default {
    name: 'shopInfo',
    data() {
        return {
            selectFrom: {},//搜索栏
            tableData: [],//表格数据
            page: 1,
            limit: 10,
            total: 0,
            height: window.innerHeight - 250, //表格高度
            fromSign: false,//添加表单标记
            fromTitle: "添加店铺",
            from: {},//店铺数据
            isUpdate: false,//是否修改
            rules: {
                name: [
                    { required: true, message: '请输入店铺名称', trigger: 'blur' },
                    { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' }
                ],
                boss: [
                    { required: true, message: '请输入老板名称', trigger: 'blur' },
                    { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' }
                ],
                phone: [
                    { required: true, message: '请输入手机号码', trigger: 'blur' },
                    { min: 11, max: 11, message: '手机号码长度错误', trigger: 'blur' },
                    {
                        pattern: /^1[3456789]\d{9}$/,
                        message: "请输入正确的手机号",
                        trigger: "blur",
                    },
                ],
                schoolId: [
                    { required: true, message: '请选择入驻校区', trigger: 'change' }
                ],
                address: [
                    { required: true, message: '请输入店铺位置', trigger: 'blur' },
                    { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
                ],
            },
            loading: false,//添加表格
            tableloading: false,//表格数据
        }
    },
    mounted() {
        this.getShopInfoData();
        //-------------------------表格响应----------------//
        this.createHeight();
        //当页面发生变化时，表格高度固定
        window.onresize = () => {
            return (() => {
                this.$nextTick(() => {
                    this.createHeight();
                });
            })();
        };
    },
    methods: {
        //解冻
        thawShopInfoData(row){
            thawShopInfo(row).then(res=>{
                this.getShopInfoData();
            })
        },
        //冻结
        freezeShopInfoData(row){
            freezeShopInfo(row).then(res=>{
                this.getShopInfoData();
            })
        },
        //获取店铺数据
        getShopInfoData() {
            this.selectFrom.page = this.page;
            this.selectFrom.limit = this.limit;
            this.tableloading = true;
            getShopInfoBack(this.selectFrom).then(res => {
                this.tableData = res.dataList;
                this.total = res.total;
                this.tableloading = false;
            })
        },
        handleSizeChange(val) {
            this.limit = val;
            this.getShopInfoData();
        },
        handleCurrentChange(val) {
            this.page = val;
            this.getShopInfoData();
        },
        //---------------自动变更表格高度------------------//
        createHeight() {
            this.height = window.innerHeight - 250;
        }
    }
}
</script>
  